﻿using UnityEngine;
using System.Collections;

public class ShipController2 : MonoBehaviour {
	
	public GameObject target;
	public GameObject ship;
	public float acceleration = 100;
	
	public float minSpeed = -100;
	public float maxSpeed = 100;
	public int maxHealth = 100;
	public int currentHealth = 100;
	
	public int maxShield = 100;
	public int currentShield = 100;
	
	
	private float speed = 0;
	
	
	public Transform ExplosionPrefab;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void FixedUpdate () {
		//interpoliert von start(transform.target) zu ziel (targetvector)
		transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position, transform.up), Time.deltaTime*3); 
		//same here just for the ship model, transform.up um rumspacken zu verhindern as durch world.up ausgelöst wird
		ship.transform.rotation = Quaternion.Slerp(ship.transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position, transform.up), Time.deltaTime *5);
		
		speed += Input.GetAxis("Vertical")*acceleration * Time.deltaTime;
		speed = Mathf.Clamp(speed, minSpeed, maxSpeed);
		
		transform.Translate(Vector3.forward * speed * Time.deltaTime);
		
	}
	
	void OnCollisionEnter (Collision col) {
		
		
			Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
		
	}
	
	void Update()
	{
		if(currentHealth> maxHealth)
		{
			currentHealth  = maxHealth;
		}
		
		if(currentShield > maxShield)
		{
			currentShield = maxShield;
		}
		
		
		
	}
}
